package com.ruoyi.web.controller.exam_syllabus;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.exam_syllabus.domain.TsExamSyllabus;
import com.ruoyi.exam_syllabus.service.ITsExamSyllabusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 考试大纲设置Controller
 *
 * @author hongyi
 * @date 2023-12-08
 */
@RestController
@RequestMapping("/exam_syllabus/syllabus")
public class TsExamSyllabusController extends BaseController
{
    @Autowired
    private ITsExamSyllabusService tsExamSyllabusService;

    /**
     * 查询考试大纲设置列表
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:list')")
    @GetMapping("/list")
    public TableDataInfo list(TsExamSyllabus tsExamSyllabus)
    {
        startPage();
        List<TsExamSyllabus> list = tsExamSyllabusService.selectTsExamSyllabusList(tsExamSyllabus);
        return getDataTable(list);
    }

    /**
     * 导出考试大纲设置列表
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:export')")
    @Log(title = "考试大纲设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TsExamSyllabus tsExamSyllabus)
    {
        List<TsExamSyllabus> list = tsExamSyllabusService.selectTsExamSyllabusList(tsExamSyllabus);
        ExcelUtil<TsExamSyllabus> util = new ExcelUtil<TsExamSyllabus>(TsExamSyllabus.class);
        util.exportExcel(response, list, "考试大纲设置数据");
    }

    /**
     * 获取考试大纲设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:query')")
    @GetMapping(value = "/{examSyllabusId}")
    public AjaxResult getInfo(@PathVariable("examSyllabusId") Long examSyllabusId)
    {
        return success(tsExamSyllabusService.selectTsExamSyllabusByExamSyllabusId(examSyllabusId));
    }

    /**
     * 新增考试大纲设置
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:add')")
    @Log(title = "考试大纲设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TsExamSyllabus tsExamSyllabus)
    {
        return toAjax(tsExamSyllabusService.insertTsExamSyllabus(tsExamSyllabus));
    }

    /**
     * 修改考试大纲设置
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:edit')")
    @Log(title = "考试大纲设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TsExamSyllabus tsExamSyllabus)
    {
        return toAjax(tsExamSyllabusService.updateTsExamSyllabus(tsExamSyllabus));
    }

    /**
     * 删除考试大纲设置
     */
    @PreAuthorize("@ss.hasPermi('exam_syllabus:syllabus:remove')")
    @Log(title = "考试大纲设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{examSyllabusIds}")
    public AjaxResult remove(@PathVariable Long[] examSyllabusIds)
    {
        return toAjax(tsExamSyllabusService.deleteTsExamSyllabusByExamSyllabusIds(examSyllabusIds));
    }
}
